package domfarr.web.tapestry.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.Service;
import org.apache.tapestry5.ioc.annotations.Inject;

import domfarr.entities.Contact;
import domfarr.web.tapestry.services.ContactService;

public class Start {
	@Property
	private Contact contact;
	
	@Inject
	@Service("contactService")
	private ContactService contactService;
	
	@InjectPage
	private ContactAdded contactAdded;

	public String getMessage() {
		return "Add Contact";
	}
	
	public Object onSuccess() {
		
		Contact savedContact = contactService.save(this.contact);
		
		contactAdded.setName(savedContact.getFullName());
		
		return contactAdded;
	}
}
